<template>
	<view class="content">
		<view class="mapView">
			<map name="北京市" :longitude="longitude" :latitude="latitude" :markers="markers"></map>
		</view>
		<view class="cu-bar bg-white solid-bottom">
			<view class="action text-bold">
				<text class="cuIcon-title text-29a1b1"></text>
				<text>{{homeData.companyName}}</text>
			</view>
		</view>
		<view class="cu-bar bg-white solid-bottom">
			<view class="action">
				<text>地址：</text>
				<text @click="navigateToLocation" class="text-29a1b1">{{homeData.address}}</text>
			</view>
		</view>
		<view class="cu-bar bg-white solid-bottom">
			<view class="action">
				<text>电话：</text>
				<text @click="call(homeData.telephone)" class="text-29a1b1">{{homeData.telephone}}</text>
			</view>
		</view>
		<view class="cu-bar bg-white solid-bottom">
			<view class="action">
				<text>手机：</text>
				<text @click="call(homeData.phone)" class="text-29a1b1">{{homeData.phone}}</text>
			</view>
		</view>
		<view class="cu-bar bg-white solid-bottom">
			<view class="action">
				<text>传真：</text>
				<text>{{homeData.facsimile}}</text>
			</view>
		</view>
		<view class="cu-bar bg-white solid-bottom">
			<view class="action">
				<text>邮件：</text>
				<text>{{homeData.mailbox}}</text>
			</view>
		</view>
	</view>
</template>

<script>
	import markerIcon from '../../static/home/markerImg.png'
	export default {
		data() {
			return {
				latitude: "",
				longitude: "",
				markers: [],


				// 首页数据
				homeData: {}
			}
		},
		onLoad() {},
		onShow() {
			const vm = this;
			vm.homeData = uni.getStorageSync("homeData")

			// 地图相关
			vm.addRandomMarker();
		},
		methods: {
			addRandomMarker() {
				const vm = this;

				// vm.latitude = 39.084158 + Math.random() * 0.1; // 生成随机纬度
				// vm.longitude = 117.200983 + Math.random() * 0.1; // 生成随机经度

				vm.latitude = vm.homeData.latitude;
				vm.longitude = vm.homeData.longitude;

				vm.markers = [{
					"id": 888,
					"latitude": vm.latitude,
					"longitude": vm.longitude,
					"iconPath": markerIcon,
					// "width": "auto",
					// "height": "auto"
				}]

			},

			navigateToLocation() {
				const vm = this;

				// const latitude = vm.homeData.latitude; // 替换为实际的纬度
				// const longitude = vm.homeData.longitude; // 替换为实际的经度
				// const name = vm.homeData.address; // 目标位置
				var data = {
					latitude: parseFloat(vm.homeData.latitude),
					longitude: parseFloat(vm.homeData.longitude),
					name: vm.homeData.address,
				}

				console.log(data)
				uni.openLocation({
					latitude: data.latitude, // 纬度
					longitude: data.longitude, // 经度
					name: data.name,
					scale: 18, // 缩放级别，范围5-18，默认为18
					success: (res) => {
						console.log(res)
					},
					fail: (res) => {
						console.log('失败', res)
					}
				});
			}
		}
	}
</script>

<style lang="less" scoped>
	.content {
		padding: 0;
	}

	.mapView {
		width: 100%;
		height: calc(100vh - 800upx);

		map {
			width: 100%;
			height: 100%;
		}
	}
</style>